class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_filter :check_login,:set_cache_buster




  helper_method :current_user,:has_logged_in

  private
  
  def current_user
    @current_user ||= User.find(session[:user_name]) if session[:user_name]
  end

  def has_logged_in
  end

  def check_login
    if(!session[:user_name])
      flash.now.notice="Please login first"
      redirect_to user_homepage_path , :notice => "Please login first."
    end
  end



  def set_cache_buster
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  end


end
